<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"
        :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="类型">
            <el-select v-model="form.type" placeholder="请选择" style="width: 370px;">
              <el-option v-for="item in optionsType" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="客户号">
            <el-input v-model="form.uid" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="分数">
            <el-input v-model="form.code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="答案">
            <el-input v-model="form.answer" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="问题编号">
            <el-input v-model="form.questionId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="题目">
            <el-input v-model="form.questionName" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;"
        @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="type" label="类型">
          <template slot-scope="scope">
            {{scope.row.type=='1' ? "单选" : scope.row.type=='2' ? '多选' : scope.row.type=='3' ? '判断': '错误'}}
          </template>
        </el-table-column>
        <el-table-column prop="uid" label="客户号" />
        <el-table-column prop="code" label="分数" />
        <el-table-column prop="answer" label="答案" />
        <el-table-column prop="questionId" label="问题编号" />
        <el-table-column prop="questionName" label="题目" />
        <el-table-column prop="createdAt" label="创建时间" />
        <el-table-column prop="updatedAt" label="修改时间" />
        <!-- <el-table-column v-if="checkPer(['admin','dccQuestionAnswer:edit','dccQuestionAnswer:del'])" label="操作"
          width="150px" align="center">
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission" />
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
  import crudDccQuestionAnswer from '@/api/dccQuestionAnswer'
  import CRUD, {
    presenter,
    header,
    form,
    crud
  } from '@crud/crud'
  import rrOperation from '@crud/RR.operation'
  import crudOperation from '@crud/CRUD.operation'
  import udOperation from '@crud/UD.operation'
  import pagination from '@crud/Pagination'

  const defaultForm = {
    id: null,
    status: null,
    type: null,
    uid: null,
    code: null,
    answer: null,
    questionId: null,
    questionName: null,
    operator: null,
    createdAt: null,
    updatedAt: null
  }
  export default {
    name: 'DccQuestionAnswer',
    components: {
      pagination,
      crudOperation,
      rrOperation,
      udOperation
    },
    mixins: [presenter(), header(), form(defaultForm), crud()],
    cruds() {
      return CRUD({
        title: '毒查查闯关记录',
        url: 'api/dccQuestionAnswer',
        idField: 'id',
        sort: 'id,desc',
        crudMethod: {
          ...crudDccQuestionAnswer
        }
      })
    },
    data() {
      return {
        optionsType: [{
          value: '1',
          label: '单选'
        }, {
          value: '2',
          label: '多选'
        }, {
          value: '3',
          label: '判断'
        }],
        permission: {
          add: ['admin', 'dccQuestionAnswer:add'],
          edit: ['admin', 'dccQuestionAnswer:edit'],
          del: ['admin', 'dccQuestionAnswer:del']
        },
        rules: {},
      }
    },
    methods: {
      // 钩子：在获取表格数据之前执行，false 则代表不获取数据
      [CRUD.HOOK.beforeRefresh]() {
        return true
      }
    }
  }
</script>

<style scoped>

</style>